package com.shengqiang.cloud.ups.controller;

import com.shengqiang.cloud.ups.common.model.JsonResult;
import com.shengqiang.cloud.ups.dao.modal.UpmsDepartment;
import com.shengqiang.cloud.ups.service.UpmsDepartmentWebService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/21.
 */
@Controller
@RequestMapping(value = "department")
public class DepartmentController {

    private static final Logger logger= LoggerFactory.getLogger(DepartmentController.class);

    @Autowired
    private UpmsDepartmentWebService departmentWebService;

    @RequestMapping(value = "toDepartment",method = {RequestMethod.GET,RequestMethod.POST})
    public String toDepartment(){
        return "/user/department";
    }

    @RequiresPermissions(value = "upms:users:department:list")
    @ResponseBody
    @RequestMapping(value = "select",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult<List<UpmsDepartment>> selectDepartments(@RequestParam Map<String,Object> params){
        return departmentWebService.selectDepartments(params);
    }

    @RequiresPermissions(value = "upms:users:department:add")
    @ResponseBody
    @RequestMapping(value = "addDepartment",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult addDepartment(UpmsDepartment department){
        return departmentWebService.addDeparatment(department);
    }

    @RequiresPermissions(value = "upms:users:department:edit")
    @ResponseBody
    @RequestMapping(value = "updateDepartment",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult updateDepartment(UpmsDepartment department){
        return departmentWebService.updateDepartment(department);
    }

    @RequiresPermissions(value = "upms:users:department:delete")
    @ResponseBody
    @RequestMapping(value = "deleteDepartments",method = {RequestMethod.POST,RequestMethod.GET})
    public JsonResult deleteDepartment(@RequestParam("departmentIds[]") List<Integer> departmentIds){
        return departmentWebService.deleteDepartment(departmentIds);
    }
}
